package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.oldplayerreturn.OldPlayerReturnUserData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eMallCategory;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.oldplayerreturn.OldPlayerReturnMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class OldPlayerMallLimit extends BaseActivityMallLimit {
    public OldPlayerMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if (!ActivityMgr.activityInTime(activityInfo)) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        if (activityInfo.getType() != eActivityType.OldPlayerReturn.getValue()) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.OldPlayerReturn.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        if (!player.getModule(OldPlayerReturnModule.class).checkUserIsReturn()) {
            return GameErrorCode.E_PLAYER_RETURN_NOT_RETURN_ROLE;
        }
        OldPlayerReturnUserData userData = OldPlayerReturnMgr.getUserData(player.getUserId());
        if (userData == null){
            return GameErrorCode.E_PLAYER_RETURN_NOT_RETURN_ROLE;
        }
        if (mallInfo.getCategory() == eMallCategory.ReturnRoleOnlyPrivilegeCard.getValue()){
            if (userData.isHadBuyCheapCard()){
                return GameErrorCode.E_PLAYER_RETURN_BUY_REACH_LIMIT;
            }
        }
        if (userData.getRmbMallLimit().containsKey(mallInfo.getMallId())){
            if (userData.getRmbMallLimit().get(mallInfo.getMallId()) >= mallInfo.getLimitBuyCount()){
                return GameErrorCode.E_PLAYER_RETURN_BUY_REACH_LIMIT;
            }
        }
        return 0;
    }
}
